chcp 65001 >nul
@echo off

@REM 端口转发：         netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=80 connectaddress=子系统IP connectport=80
@REM 开放防火墙端口:     netsh advfirewall firewall add rule name="Allow Port 80" dir=in action=allow protocol=TCP localport=80

@REM 需要修改为子系统的IP
set IP=192.168.1.1
if "%IP%"=="192.168.1.1" set /p "IP=请输入IP地址: "

if "%IP%"=="" (
    echo Error: IP address cannot be empty!
    exit /b 1
)
:: 基本格式检查
echo !IP! | findstr /r "^[0-9][0-9.]*$" >nul
if errorlevel 1 (
    echo 错误：IP地址只能包含数字和点号
    exit /b 1
)

@REM --------------------------------------------------
@REM --------------------------------------------------
@REM 前面是验证IP的操作，下面是配置端口
@REM --------------------------------------------------
@REM --------------------------------------------------



@REM 配置22端口转发
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=22 connectaddress=%IP% connectport=22
netsh advfirewall firewall add rule name="Allow Port 22" dir=in action=allow protocol=TCP localport=22

@REM 配置5022端口转发
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=5022 connectaddress=%IP% connectport=5022
netsh advfirewall firewall add rule name="Allow Port 5022" dir=in action=allow protocol=TCP localport=5022


@REM 查看端口转发
netsh interface portproxy show all


endlocal